package com.sky.controller.user;

import com.sky.dto.NotifyDto;
import com.sky.service.user.WxPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/wx")
public class NotiryController {

    @Autowired
    private WxPayService wxPayService;
    @PostMapping("/jsapiNotify")
    public Map jsApiNotify(@RequestBody NotifyDto notifyDto){
        System.out.println("模拟数据的解析");


        return new HashMap();
    }

    @PostMapping("/nativeNotify")
    public Map nativeNotify(@RequestBody NotifyDto notifyDto){
        System.out.println("二维码支付回调通知执行了");
        Map map = new HashMap();

        try {
            wxPayService.handleNotify(notifyDto);
        }catch (Exception e){
            map.put("code", "FAIL");
            map.put("message", "失败");
            return map;
        }

        return map;
    }
}
